<?php


namespace app\library\create\lib;


class UpdateRouter
{
    public static function update($name)
    {
        $path = root_path('app/admin/route');
        $file = 'admin.php';
        if (!file_exists($path . $file)) {
            $routeFile = root_path('app/library/template') . 'AdminRout.template';
            $routeFileStr = file_get_contents($routeFile);
            CreateFile::createFile($path, $file, $routeFileStr);
        }
        $routeFileStr = $routeFileStr ?? file_get_contents($path . $file);
        $str = "Route::resource('" . strtolower($name) . "','$name');" . PHP_EOL;//准备要写入的路由文件
        str_contains($routeFileStr, $str) || CreateFile::updateTailToFile($path . $file, $str);
    }
}